package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;

/**
 * 分析：同POJ1850
 * 
 * 实现：
 * 
 * 经验：
 * 
 * 教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1496 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1496.class.getResource("P1496.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		while (line != null) {
			System.out.println(code(line.toCharArray()));
			line = stdin.readLine();
		}
	}

	private static long code(char[] cs) {

		//check first
		if (cs.length == 0) return 0;
		for (int i = 0; i < cs.length; i ++) {
			if (cs[i] < 'a' || cs[i] > 'z') return 0;
			if (i != 0) {
				if (cs[i] <= cs[i-1]) return 0;
			}
		}
		
		//calculate code
		long c = 0;
		for (int i = 1; i < cs.length; i ++) {
			c += c(26, i);
		}
		return c + count(cs) + 1;
	}
	
	/**
	 * 计算和cs长度一样，但小于cs的字符串个数
	 * @param cs
	 * @return
	 */
	private static long count(char[] cs) {

		if (cs.length == 0) {
			return 0;
		} else if (cs.length == 1) {
			return cs[0]-'a';
		} else {
			long c = 0;
			for (char f = 'a'; f < cs[0]; f = (char)(f+1)) {
				int n = cs.length-1;
				int m = 'z'-f;
				c += c(m, n);
			}
			
			char[] ncs = new char[cs.length-1];
			for (int i = 0; i < ncs.length; i ++) ncs[i] = cs[i+1];
			return c + count(ncs, (char)(cs[0]+1));
		}
	}
	
	/**
	 * 计算和cs长度一样，所有字符不小于min，但本身小于cs的cs的字符串个数
	 * @param cs
	 * @param min
	 * @return
	 */
	private static long count(char[] cs, char min) {
		
		if (cs.length == 0) {
			return 0;
		} else if (cs.length == 1) {
			return cs[0] - min;
		} else {
			long c = 0;
			for (char f = min; f < cs[0]; f = (char)(f+1)) {
				int n = cs.length-1;
				int m = 'z'-f;
				c += c(m, n);
			}
			
			char[] ncs = new char[cs.length-1];
			for (int i = 0; i < ncs.length; i ++) ncs[i] = cs[i+1];
			return c + count(ncs, (char)(cs[0]+1));				
		}
	}

	/**
	 * C(m,n)
	 * @param m
	 * @param n
	 * @return
	 */
	private static long c(long m, long n) {
		
		if (m < n) return 0;
		long r = 1;
		for (long i = 0; i < (long)Math.min(m-n, n); i ++) {
			r *= (m-i);
			r /= i+1;
		}
		return r;
	}
}